package com.sjzs.web.dao;

import java.util.Date;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sjzs.web.po.User00;
import com.sjzs.web.po.User01;
import com.sjzs.web.util.DateUtil;



public class User00Dao extends HibernateDaoSupport {
	@SuppressWarnings("unchecked")
	/**
	 *  用户登录
	 */
	public User00 userLogin(String userName,String pwd){
		List<User00> lstUsers = this.getHibernateTemplate().find("from User00 where 1=1 and ZHM000 = ? and ZHMM00=? ",userName,pwd);
		if (lstUsers == null || lstUsers.isEmpty()) {
			return null;
		} else {
			return lstUsers.get(0);
		}
	}
	/**
	 * 保存用户
	 * @param user
	 */
	public void saveUser(User00 user) {
		String id=this.getSession().createSQLQuery("select SEQ_USER_ID.nextval from dual").uniqueResult().toString();
		user.setDevuid(id);	
		user.setZhs000("000");
		user.setSfjh00("000");
		user.setYhlx00("000");
	    user.setCjsj00(DateUtil.dateToString("yyyy-MM-dd HH:mm:ss", new Date()));
		this.getHibernateTemplate().save(user);
	}
	/**
	 * 根据账户名查找用户
	 * @param userName
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public User00 queryUserByZhm00(String userName){
		List<User00> lstUsers = this.getHibernateTemplate().find("from User00 where 1=1 and ZHM000 = ?",userName);
		if (lstUsers == null || lstUsers.isEmpty()) {
			return null;
		} else {
			return lstUsers.get(0);
		}
	}
	
	@SuppressWarnings("unchecked")
	public User00 queryUserByNC(String usernc){
		List<User00> lstUsers = this.getHibernateTemplate().find("from User00 where 1=1 and nc0000 = ?",usernc);
		if (lstUsers == null || lstUsers.isEmpty()) {
			return null;
		} else {
			return lstUsers.get(0);
		}
	}
	/**
	 * 根据用户id获取用户基本信息
	 * @param devuid
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public User00 queryUserByDevuid(String devuid){
		List<User00> lstUsers = this.getHibernateTemplate().find("from User00 where 1=1 and devuid = ?",devuid);
		if (lstUsers == null || lstUsers.isEmpty()) {
			return null;
		} else {
			return lstUsers.get(0);
		}
	}
	/**
	 * 根据用户id 获取用户信息
	 * @param devuid
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public User01 queryUser01ByDevuid(String devuid){
		List<User01> lstUsers = this.getHibernateTemplate().find("from User01 where 1=1 and devuid = ?",devuid);
		if (lstUsers == null || lstUsers.isEmpty()) {
			return null;
		} else {
			return lstUsers.get(0);
		}
	}
	/**
	 * 更新用户
	 * @param user00
	 */
   public void updateByUser(User00 user00){
	 this.getHibernateTemplate().update(user00);
   }
   
   public void updateByUser01(User01 user01){
	   this.getHibernateTemplate().saveOrUpdate(user01);
   }
}
